%!TEX program = xelatex
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt,t,aspectratio=169,mathserif]{beamer}
%Other possible values are: 1610, 149, 54, 43 and 32. By default, it is to 128mm by 96mm(4:3).
%run XeLaTeX to compile.

\input{wang-slides-preamble.tex}

\begin{document}

\title{第5章：二维图形}
%(1.1-1.2) 
%\institute{上海立信会计金融学院}
\author{JMS LQW}
%\date{2021年3月12日}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{frame}[fragile=singleslide]{6.1.1. }
\begin{frame}{目录 }

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{enumerate}
\item[5.1.]  概述  
\item[5.2.]  绘图入门：前端与后端、简单图形
\item[5.3.]  面向对象的 Matplotlib
\item[5.4.]  笛卡尔坐标绘图：曲线样式、标记样式
\item[5.5.]  极坐标绘图 
\item[5.6.]  误差条  
\item[5.7.]  文本与注释
\item[5.8.]  显示数学公式
\item[5.9.]  等高线图
\item[5.10.]  复合图形
\item[5.11.]  Mandelbrot 集合

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.1. 概述}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：有哪些科学计算图形包？
%\item  答：
\begin{itemize}
\item  Gnuplot  --  \url{http://www.gnuplot.info}
\item  Matlab  --  \url{https://www.mathworks.com}
\item  Matplotlib  --  \url{https://matplotlib.org}
\end{itemize}

\item  问：Matplotlib 项目的目标是什么？

\item  问：matplotlib 图形示例库中有哪些类型的图形？

\url{https://matplotlib.org/stable/gallery/index.html}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2.1. 前端}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：什么是前端？

%\item  问：下述代码的作用是什么？
%\begin{python}
%ipython --pylab
%\end{python}

\item  问：Matplotlib 模块里的 pyplot 子模块，有哪些画图功能？
\begin{python}
import matplotlib.pyplot as plt
plt.<TAB>
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2.2. 后端 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：后端要解决哪些问题？

\item  问：如何显示本机实际使用的后端？
\begin{python}
import matplotlib.pyplot as plt
plt.get_backend()
\end{python}

\item  问：如何显示本机可用的后端列表？
\begin{python}
>>> %matplotlib -l
Available matplotlib backends: ['tk', 'gtk', 'gtk3', 'wx', 
'qt4', 'qt5', 'qt', 'osx', 'nbagg', 'notebook', 'agg', 'svg', 
'pdf', 'ps', 'inline', 'ipympl', 'widget']
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2.3. 一个简单示例图形}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 IPython 解释器的三种方式，分别是什么？
\begin{enumerate}
\item  终端模式 terminal mode
\item  非内联笔记本模式 non-inline notebook mode
\item  内联笔记本模式  \%matplotlib notebook 
\end{enumerate}

\begin{python}
import numpy as np
import matplotlib.pyplot as plt

# use the next command in IPython terminal mode
plt.ion()

# use the next command in IPython non-inline notebook mode
#%matplotlib

# use the next command in IPython inline notebook mode
#%matplotlib notebook
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2 3. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画出下述函数的图像， $$y=\sin(x) + \frac{1}{3}\sin(3x), \,\,\, -\pi \le x \le \pi.$$

\begin{python}
x = np.linspace(-np.pi, np.pi, 101)
y = np.sin(x) + np.sin(3*x)/3.0

plt.plot(x,y)
plt.xlabel('x')
plt.ylabel('y')
plt.title('A simple plot')

#plt.show()
plt.savefig('pic/fig-5-2-3.png')
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2.3.  }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-5-2-3.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.2.4. 交互式操作 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：测试 matplotlib 图形窗口的交互式按钮。

\begin{python}
>>> %matplotlib?  #看说明书
>>> %matplotlib  #显示独立的图形窗口
>>> %matplotlib inline  #解释器内部显示图形
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.3. 面向对象的 Matplotlib }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：什么是 \pyth{Figure} 类和 \pyth{Axes} 类？下述代码中哪两行定义了这两个类？

\begin{python}
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi, 101)
y = np.sin(x) + np.sin(3*x)/3.0

fig = plt.figure()   #创建一个 Figure 对象
ax = fig.add_subplot(111)   #创建一个 Axes 对象
ax.plot(x,y)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('A simple plot')
fig.savefig('pic/fig-5-3.png')
\end{python}

%\inputpython{python_file.py}{23}{50} 插入地23-50行代码

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.1. 笛卡尔坐标绘图 - 绘图函数}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：Matplotlib.pyplot 的二维绘图的函数是什么？如何使用？

\begin{python}
ax.plot(x,y)
ax.plot(x,y,x,z)
ax.plot(x,y,fmt)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.2. 曲线样式 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：曲线样式包括颜色、线条样式、宽度。
\begin{python}
ax.plot(x,y,'m-.',linewidth=2)
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.2. 曲线样式 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：写出下述字符代表的颜色和线条样式。

\begin{tabular}{c|c}
character & colour \\ \hline
b& blue \\ 
g& green \\ 
r& red \\ 
c& cyan \\ 
m& magenta \\ 
y& yellow \\ 
k& black \\ 
w& white \\ 
\end{tabular}
\hspace{1cm}
\begin{tabular}{c|c}
character & line style \\ \hline
- & solid curve \\ 
-- & dashed curve \\ 
-. & dash-dot curve \\ 
: & dotted curve \\  
\end{tabular}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.3. 标记样式 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：写出下列字符代表的标记样式。
\begin{python}
ax.plot(x,y,'o',markerfacecolor='blue',markersize=2.5)
\end{python}

\begin{tabular}{c|c}
character & marker style \\ \hline
.& point \\ 
o& circle \\ 
*& star \\ 
+& plus \\ 
x& x \\ 
v& triangle down \\
\end{tabular}
\hspace{1cm}
\begin{tabular}{c|c}
character & marker style \\ \hline
$\wedge$& triangle up \\ 
<& triangle left \\
>& trianglee right \\
n& square \\
p& pentagon \\
h& hexagon \\
\end{tabular}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.4. 坐标轴、网格线、标签、标题 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：如何设置对数坐标轴？
\begin{python}
ax.semilogx(x,y)
ax.semilogy(x,y)
ax.loglog(x,y)
\end{python}

\item  问：如何为每条曲线添加标签？
\begin{python}
ax.plot(x,y,label='string')
ax.legend(loc='best')
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.5. 一个稍复杂的示例：傅立叶级数的部分和 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画出下述傅立叶级数的前几个部分和的图形，
$$F(x) = \frac{4}{\pi} \sum\limits_{k=0}^{\infty} \frac{\sin((2k+1)x)}{2k+1}. $$

\item  问：证明上述傅立叶级数收敛于函数 
$$f(x) = \left\{ \begin{array}{ll} -1, & \text{若}\,\, -\pi<x<0, \\ 1, & \text{若}\,\, 0\le x\le\pi. \end{array}\right.$$

\end{itemize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.5. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(-np.pi,np.pi,101)
f=np.ones_like(x)
f[x<0]=-1
y1=(4/np.pi)*(np.sin(x)+np.sin(3*x)/3.0)
y2=y1+(4/np.pi)*(np.sin(5*x)/5.0+np.sin(7*x)/7.0)
y3=y2+(4/np.pi)*(np.sin(9*x)/9.0+np.sin(11*x)/11.0)
\end{python}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.5. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x,f,'b-',lw=3,label='f(x)')
ax.plot(x,y1,'c--',lw=2,label='two terms')
ax.plot(x,y2,'r-.',lw=2,label='four terms')
ax.plot(x,y3,'b:',lw=2,label='six terms')
ax.legend(loc='best')
ax.set_xlabel('x',style='italic')
ax.set_ylabel('partial sums',style='italic')
fig.subtitle('Partial sums for Fourier series of f(x)',
             size=16,weight='bold')
fig.savefig('pic/fig-5-4-5.png')
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.4.5.  }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-5-4-5.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.5. 极坐标绘图}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画出极坐标定义的三个函数的图像， 
\begin{eqnarray*}
r &=& |\cos(5\theta) - 1.5\sin(3\theta)|, \\
r &=& \theta/\pi, \\
r &=& 2.25.
\end{eqnarray*}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.5. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
import numpy as np
import matplotlib.pyplot as plt

theta=np.linspace(0,2*np.pi,201)
r1=np.abs(np.cos(5.0*theta)-1.5*np.sin(3.0*theta))
r2=theta/np.pi
r3=2.25*np.ones_like(theta)

fig=plt.figure()
ax=fig.add_subplot(111,projection='polar')
ax.plot(theta,r1,label='trig')
ax.plot(5*theta,r2,label='spiral')
ax.plot(theta,r3,label='circle')
ax.legend(loc='best')
\end{python}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.5.  }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.5\textwidth]{pic/fig-5-5.png}
% \caption{ }
\end{figure}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.6. 误差条}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画一个使用误差条的简单图形。

\begin{python}
import numpy as np
import numpy.random as npr
x=np.linspace(0,4,21)
y=np.exp(-x)
xe=0.08*npr.randn(len(x))
ye=0.1*npr.randn(len(y))

import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
ax.errorbar(x,y,fmt='bo',lw=2,xerr=xe,yerr=ye,
            ecolor='r',elinewidth=1)
fig.savefig('pic/fig-5-6.png')
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.6. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-5-6.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.7. 文本和注释}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：如何在图形的坐标 $(x,y)$ 开始的位置，放一个文本字符串？

\begin{python}
ax.text(x,y,'some text')
\end{python}

\item  问：如何在图形中标注一个特征？
\begin{python}
ax.annotate('text', xy, xytext, arrowprops)
\end{python}


\end{itemize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.7. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
import numpy as np
x=np.linspace(0,2,101)
y=(x-1)**3+1
import matplotlib.pyplot as plt

fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x,y)
ax.annotate('point of inplection at x=1',xy=(1,1),
					xytext=(0.8,0.5),
					arrowprops=dict(facecolor='black', width=1, 
								shrink=0.05))
\end{python}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.7. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-5-7.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.8. 显示数学公式}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：如何在图形中显示美观的数学公式？

\begin{python}
ax.set_title(r'The level contours of $z=x^2-y^2$')
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.9. 等高线图}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画出二元函数 $z=x^2-y^2$ 的等高线图。用填充颜色的方式。
\begin{python}
import numpy as np
import matplotlib.pyplot as plt
fig=plt.figure()
ax=fig.add_subplot(111)
[X,Y]=np.mgrid[-3:3:61j,-3:3:61j]
Z=X**2-Y**2
curves=ax.contour(X,Y,Z,12,colors='b')
ax.clabel(curves)

#im=ax.contourf(X,Y,Z,12)
#fig.colorbar(im,orientation='vertical')

fig.suptitle(r'The level contour of $z=x^2-y^2$',fontsize=20)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.9. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-5-9.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.9. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-5-9-fill.png}
% \caption{ }
\end{figure}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.10. 复合图形 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：如何在同一个图形中呈现几个绘图？
\begin{python}
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,5,101)
y1=1.0/(x+1.0); y2=np.exp(-x); 
y3=np.exp(-0.1*x**2); y4=np.exp(-5*x**2)

fig=plt.figure()
ax1=fig.add_subplot(221); ax1.plot(x,y1)
ax2=fig.add_subplot(222); ax2.plot(x,y2)
ax3=fig.add_subplot(223); ax3.plot(x,y3)
ax4=fig.add_subplot(224); ax4.plot(x,y4)
fig.suptitle('Various decay functions')
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.10. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-5-10.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. Mandelbrot 集合}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：什么是 Mandelbrot 集合？

答：设 $c$ 是一个复数。如果数列 $$z_0=c, z_{n+1}=z_n^2+c, n\ge 0$$
在复数平面中是有界集合，则定义 $c$ 是 Mandelbrot 集合中的一个元素。

\vspace{0.5cm}

\item  证明：若 $|c|\ge 2$, 则 $c$ 不属于 Mandelbrot 集合。

\item  证明：设 $|c|<2$. 如果对某个 $n\ge 1$ 有 $|z_n|>2$, 则 $c$ 不属于 Mandelbrot 集合。

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：什么是逃逸参数？

\item  问：将 Mandelbrot 集合可视化的一个方法是什么？

\item  问：画出 Mandelbrot 集合。

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. (1) }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
import numpy as np
from time import time

#Set the parameters
max_iter=256  #maximum number of iterations
nx,ny=1024,1024   #x- and y-image resolution
#x_lo,x_hi=-2.0,1.0  #x bounds in complex plain: x_low and x_hi
#y_lo,y_hi=-1.5,1.5  #y bounds in complex plain: y_low and y_hi
x_lo,x_hi=-2.0,-1.9998    #任意选取了极小的一个区域 <---   
y_lo,y_hi=-0.0001,0.0001    #任意选取了极小的一个区域 <---
start_time=time()
\end{python}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. (2) }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
#Construct the two-dimensional arrays
ix,iy=np.mgrid[0:nx,0:ny]
x,y=np.mgrid[x_lo:x_hi:1j*nx, y_lo:y_hi:1j*ny]
c=x+1j*y    # 找出矩形区域的格点上的所有复数
#holds pixel rgb data
esc_parm=np.zeros((ny,nx,3),dtype='uint8')

#Flatterned arrays
nxny=nx*ny
ix_f=np.reshape(ix,nxny)
iy_f=np.reshape(iy,nxny)
c_f=np.reshape(c,nxny)
z_f=c_f.copy()   #the iterated variable
\end{python}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. (3) }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
for iter in range(max_iter):
    if not len(z_f):   #all points have escaped
        break
    n=iter+1
    r,g,b=n%4*64, n%8*32, n%16*16
    z_f*=z_f
    z_f+=c_f
    #points which are escaping
    escape=np.abs(z_f)>2.0
    #Set the rgb pixel value for the escaping points
    esc_parm[iy_f[escape],ix_f[escape],:]=r,g,b
    #points not escaping
    escape=~escape
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. (4) }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
    #remove batch of newly escaped points
    ix_f=ix_f[escape]
    iy_f=iy_f[escape]
    c_f=c_f[escape]
    z_f=z_f[escape]
    
print('Time taken=',time()-start_time)

from PIL import Image
picture=Image.fromarray(esc_parm)
picture.show()
#picture.save('mandelbrot.png')
picture.save('pic/fig-5-11.png')
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11.  }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.5\textwidth]{pic/fig-5-11.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{5.11. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  练习：在 Mandelbrot 集合的边界附近中选一个区域，计算这个区域的每个点的逃逸参数，并画图。

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{frame}[fragile=singleslide]{1.20. }
\begin{frame}{参考文献}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{thebibliography}{99}
\bibitem{stewart-en} John M. Stewart. \emph{Python for Scientists}. Second Edition. Cambridge University Press. 2017. 
\bibitem{stewart-cn} 约翰.M.斯图尔特(著). 江红等(译). \emph{Python科学计算}，机械工业出版社，2019年8月第1版。

\end{thebibliography}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


